<template>
  <div>
    <h3>权限列表组件</h3>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 表单 -->
    <el-table
      :data="rightsList"
      style="width: 100%"
      :row-class-name="tableRowClassName"
      border
    >
      <el-table-column prop="authName" label="权限名称"> </el-table-column>
      <el-table-column prop="path" label="路径"> </el-table-column>
      <el-table-column prop="level" label="权限等级">
          <!-- 使用作用域插槽,将数据传到组件中 -->
        <template slot-scope="scope">
          <el-tag effect="dark" v-if="scope.row.level === '0'">一级</el-tag>
          <el-tag type="success" effect="dark" v-if="scope.row.level === '1'"
            >二级</el-tag
          >
          <el-tag type="warning" effect="dark" v-if="scope.row.level === '2'"
            >三级</el-tag
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { Service } from '../service/index'
export default {
  data() {
    return {
      rightsList: [],
    }
  },
  async created() {
    this.getRightsList()
  },
  methods: {
    //   获取权限列表
    async getRightsList() {
      const res = await Service.getRights()
      this.rightsList = res.data.data
    },
    // 设置表格行颜色
    tableRowClassName({ row }) {
      if (row.level === '2') {
        return 'warning-row'
      } else if (row.level === '1') {
        return 'success-row'
      } else if (row.level === '0') {
        return 'defalut-row'
      }
      return ''
    },
  },
}
</script>

<style >
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
.el-table .defalut-row {
  background: #e7f1f5;
}
</style>